package jy.game.components.shop;


import android.text.TextUtils;

import java.util.List;

import jy.game.BasePojo;
import jy.game.components.item.JyItemInstance;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.ElementList;
import wx.xml.simpleframework.xml.Root;

@Root(name = "shop")
public class JyShop extends BasePojo {

    @Attribute(name = "name") public                  String           name;
    @Attribute public                                 String           pic;
    @Attribute public                                 String           music;

    @ElementList(name = "sale", inline = true) public List<JyShopSale> sales;

    private                                           String           _key = "";

    //        public HashMap<JyItemInstance, Integer> GetAvaliableSales() {
//            HashMap<JyItemInstance, Integer> dictionary = new HashMap<JyItemInstance, Integer>();
//            for (JyShopSale shopSale:this.sales) {
//                String key = "shopBuyKey_" + this.key + shopSale.name;
//                if (shopSale.limit != -1) {
//                    int num = 0;
//                    if (RuntimeData.Instance.keyValues.containsKey(key)) {
//                        num = Integer.parseInt(RuntimeData.Instance.keyValues[key]);
//                    }
//                    if (num < shopSale.limit) {
//                        dictionary.put(new JyItemInstance {
//                            name = shopSale.name
//                        }, shopSale.limit - num);
//                    }
//                } else {
//                    dictionary.put(new JyItemInstance {
//                        name = shopSale.name
//                    }, -1);
//                }
//            }
//            return dictionary;
//        }


    //        public void BuyItem(String itemName, int count ) {
////            String key = "shopBuyKey_" + this.key + itemName;
////            if (RuntimeData.Instance.keyValues.containsKey(key)) {
////                int num = Integer.parseInt(RuntimeData.Instance.keyValues[key]);
////                num += count;
////                RuntimeData.Instance.keyValues[key] = num.toString();
////            } else {
////                RuntimeData.Instance.keyValues[key] = count.toString();
////            }
////        }

    // (get) Token: 0x060004B8 RID: 1208 RVA: 0x0000480F File Offset: 0x00002A0F
    public /*override*/ String getPK() {
        {
            return this.name;
        }
    }

    // (get) Token: 0x060004B9 RID: 1209 RVA: 0x00004817 File Offset: 0x00002A17
    // (set) Token: 0x060004BA RID: 1210 RVA: 0x00004836 File Offset: 0x00002A36
    public String key() {
        if (TextUtils.isEmpty(this._key)) {
            return this.name;
        }
        return this._key;
    }

    void setKey(String value) {
        this._key = value;

    }

    public JyShopSale getSale(JyItemInstance item) {
        for (JyShopSale shopSale : this.sales) {
            if (item.name.equals(shopSale.name)) {
                return shopSale;
            }
        }
        return null;
    }
}
